package com.liuyz.outputstream_;

import org.junit.Test;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class 缓冲字节输出流 {

    // 将字节输出到文件
    @Test
    public void write_1() {
        String filePath = "d:\\test.txt";
        BufferedOutputStream outputStream = null;
        try {
            outputStream = new BufferedOutputStream(new FileOutputStream(filePath));
            // write方法：如果文件不存在，会自动创建文件（目录不会）
            outputStream.write('c');
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
